<?php

namespace Modules\H5\Http\Controllers\Home;

use Modules\Common\Models\Ebooks;
use Modules\Common\Models\Renovations;
use Modules\Common\Util\Api;
use Modules\Common\Util\Database;

class Home
{
    /**
     * 获取海量书库列表
     * @Route(path=/api/h5/book-library)
     */
    public function getBookLibrary()
    {
        $eid = auth('web')->user()->eid;
        $books = Ebooks::where('eid',$eid)->get();
        return Api::success($books);
    }

    /**
     * 获取内容推荐
     * @Route(path=/api/h5/content-recommendation)
     */
    public function getContentRecommendation()
    {
        $eid = auth('web')->user()->eid;
        $recommendedBooks = Ebooks::where('is_recommend', 1)->where('is_published',1)->where('eid',$eid)->get();
        return Api::success($recommendedBooks);
    }


    /**
     * 获取付费内容
     * @Route(path=/api/h5/paid-content)
     */
    public function getPaidContent()
    {
        $eid = auth('web')->user()->eid;
        $paidContent = Ebooks::where('is_free', 2)->where('is_published',1)->where('eid',$eid)->get();
        return Api::success($paidContent);
    }
    
    
    /**
     * 获取订阅装修信息
     * @Route(path=/api/get-renovation)
     */
    public function getRenovation()
    {
        $type = request('type');
        $eid = request('eid');
        switch ($type) {
            case 'H5':
                return Api::success(Renovations::where('type', $type)->where('eid',$eid)->where('status',1)->first());
            case 'PC':
                return Api::success(Renovations::where('type', $type)->where('eid',$eid)->where('status',1)->first());
            default:
                  return null;
        }
    }
    
}